package com.feign.core.mybatis;


import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Resource
    ApplicationContext applicationContext;

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //这里之所以使用ApplicationContext，是因为在CustomInterceptor中需要用到TableMetadataService，而TableMetadataService需要从spring容器中获取，因为其初始化需要从数据库中获取所有表的辕信息
        //否则customInterceptor中的tableMetadataService会为null
        CustomInterceptor customInterceptor = applicationContext.getBean(CustomInterceptor.class);
        interceptor.addInnerInterceptor(customInterceptor);
        return interceptor;
    }

    @Bean
    public MyMetaObjectHandler myMetaObjectHandler() {
        return new MyMetaObjectHandler();
    }
}
